home *** CD-ROM | disk | FTP | other *** search
- /*
- A very simple echo T/TCP client.
- Show how to make a basic connection to a tcp service
- in T/TCP and came back to TCP if it doesn't work.
- To test it on localhost, be sure echo/tcp is enabeld
- in the services and inetd database, then write
- rx echotcp localhost.
- */
-
- if ~show("L","rexxsupport.library") then
- if ~addlib("rexxsupport.library",0,-30) then do
- say "no rexxsupport.library"
- exit
- end
- if ~show("L","rxsocket.library") then
- if ~addlib("rxsocket.library",0,-30) then do
- say "no rxsocket.library"
- exit
- end
- if ~show("L","rmh.library") then
- if ~addlib("rmh.library",0,-30) then do
- say "no rmh.library"
- exit
- end
-
- prg = ProgramName("NOEXT")
-
- if ~RMH_ReadArgs("HOST/A") then do
- call PrintFault(IoErr(),prg)
- exit
- end
-
- addr = resolve(parm.0.value)
- if addr=="-1" then call err "no host <"parm.0.value">"
-
- if ~getservbyname("SE","echo","tcp") then
- call err "echo tcp service not found"
-
- sin.AddrFamily = "INET"
- sin.AddrAddr = addr
- sin.AddrPort = se.ServPort
-
- sock = socket("INET","STREAM","IP")
- if sock<0 then call err "no socket ("errno()")"
-
- request = "echo service test"
-
- dottcp=1
-
- if sendto(sock,REQUEST,"EOF","SIN")~=length(REQUEST) then do
- err=Errno()
- if err==57 then dottcp=0
- else call err "send error ("errno()")"
- end
-
- if dottcp==0 then do
- say "(back to TCP)"
- if connect(sock,"SIN")<0 then call err "connect error ("errno()")"
- if send(sock,REQUEST)~=length(REQUEST) then call err "send error ("errno()")"
- end
-
- if recv(sock,"BUF",256)<0 then
- call err "recv error ("errno()")"
-
- say buf
- exit
-
- err: procedure expose prg
- parse arg msg
- say prg":" msg
- exit
-